package com.mrent.web.controller.front;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mrent.entity.GoodsOrderInfo;
import com.mrent.entity.Order;
import com.mrent.service.GoodsOrderService;
import com.mrent.service.OrderGoodsService;
import com.mrent.service.OrderService;
import com.mrent.service.Page;
import com.mrent.util.Constance;
import com.mrent.util.RenderUtil;


@Controller
public class MyController {
	
	@Autowired
	private OrderService orderService;
	@Autowired
	private GoodsOrderService goodsOrderService;
	
	
	
	
	/**
	 * 显示我的申请页面.
	 * 
	 * @return
	 */
	@RequestMapping("/order/my/show")
	public String showMyOrder() {
		return "front/my/home";
	}

	/**
	 * 我的申请列表.
	 * 
	 * @return
	 */
	@RequestMapping("/order/my/list/{memberName}")
	public String listMyOrder(@PathVariable String memberName,String page, HttpServletResponse response) {

		int p = 1;
		Page pp = new Page();
		try {
			p = Integer.parseInt(page);
		} catch (Exception e) {
			p = 1;
		}
		pp.setPageNo(p);
		pp.setPageSize(Constance.DEFAULT_PAGE_SIZE);

		List<Order> list = orderService.getOrderByUser(memberName,pp);

		Map<String, Object> json = new HashMap<String, Object>();
		json.put("rows", list);
		json.put("total", pp.getTotalCount());
		RenderUtil.renderJson(json, response);

		return null;
	}
	
	/**
	 * 我的订单.
	 * 
	 * @return
	 */
	@RequestMapping("/goods/order/my/list/{memberName}")
	public String listMyGoodsOrder(@PathVariable String memberName,ModelMap model){
		List<GoodsOrderInfo> myGoodsOrders = goodsOrderService.getMemberOrder(memberName);
		model.addAttribute("orders", myGoodsOrders);
		return "front/my/myGoodsOrder";
	}
	
	

}
